export default function useDateFormat() {
    return function (date: Date, format: string) {
        const padNumber = (num: number) => num.toString().padStart(2, '0');

        // 解析日期对象
        const year = String(date.getFullYear());
        const month = padNumber(date.getMonth() + 1); // 月份从0开始，所以要加1
        const day = padNumber(date.getDate());
        const hours = padNumber(date.getHours());
        const minutes = padNumber(date.getMinutes());
        const seconds = padNumber(date.getSeconds());

        // 替换格式字符串中的占位符
        return format
            .replace('YYYY', year)
            .replace('mm', month)
            .replace('dd', day)
            .replace('HH', hours)
            .replace('MM', minutes)
            .replace('SS', seconds);
    };
}
